//
//  ViewController.m
//  14-HomeWork
//
//  Created by 李昊林 on 16/8/2.
//  Copyright © 2016年 李昊林. All rights reserved.
//

#import "ViewController.h"
#import "CustomCollectionViewCell.h"
#import "ColumnCollectionReusableView.h"
#import "StyleCollectionReusableView.h"
#import "HeaderCollectionReusableView.h"

#define kCustomCollectionViewCellReuse @"reuse"

#define kHeaderCollectionReusableViewReuse @"pool1"
#define kColumnCollectionReusableViewReuse @"pool2"
#define kStyleCollectionReusableViewReuse @"pool3"


@interface ViewController () <UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout>


@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    UISegmentedControl *seg = [[UISegmentedControl alloc] initWithItems:@[@"攻略", @"单品"]];
    self.navigationItem.titleView = seg;
    UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc] init];
    flow.minimumLineSpacing = 10;
    flow.minimumInteritemSpacing = 10;
    flow.sectionInset = UIEdgeInsetsMake(0, 10, 0, 10);
    flow.itemSize = CGSizeMake((CGRectGetWidth(self.view.bounds) - 30) / 2, 100);
    
    flow.headerReferenceSize = CGSizeMake(0, 30);
    
    UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:flow];
    [self.view addSubview:collectionView];
    collectionView.delegate = self;
    collectionView.dataSource = self;
    collectionView.backgroundColor = [UIColor whiteColor];
    [collectionView registerClass:[CustomCollectionViewCell class] forCellWithReuseIdentifier:kCustomCollectionViewCellReuse];
    
    
    [collectionView registerClass:[HeaderCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:kHeaderCollectionReusableViewReuse];
    
    
    [collectionView registerClass:[ColumnCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:kColumnCollectionReusableViewReuse];
    
    
    [collectionView registerClass:[StyleCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:kStyleCollectionReusableViewReuse];
    
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        return CGSizeMake(0, 365);
    } else {
        
        return CGSizeMake(0, 30);
    }
}

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        HeaderCollectionReusableView *header = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:kHeaderCollectionReusableViewReuse forIndexPath:indexPath];
        return header;
    } else if (indexPath.section == 1) {
        ColumnCollectionReusableView *column = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:kColumnCollectionReusableViewReuse forIndexPath:indexPath];
        return column;
    } else if (indexPath.section == 2) {
        StyleCollectionReusableView *style = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:kStyleCollectionReusableViewReuse forIndexPath:indexPath];
        
        return style;
    } else if (indexPath.section == 3) {
        ColumnCollectionReusableView *column = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:kColumnCollectionReusableViewReuse forIndexPath:indexPath];
        
        return column;
    } else {
        return nil;
    }
}






- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    
    return 4;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    if (section == 0) {
        return 0;
    } else if (section == 1) {
        return 6;
    } else if (section == 2) {
        return 6;
    } else if (section == 3) {
        return 6;
    } else {
        return 0;
    }
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    CustomCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kCustomCollectionViewCellReuse forIndexPath:indexPath];
    cell.backgroundColor = [UIColor grayColor];
    return cell;
    
    
    
    
}













@end
